<?php


namespace App\Notifications\Wechat;


use App\Internals\UserInternal;

class OrderCanceled extends Notification
{
    public function notify($userId, $tradeNo, $name, $actualPrice, $courseLevels)
    {
        $templateId = 'W2ttIH8hXqyMD4G6RA6dLzKseOhqTKvO3LvJbb0cMUo';
        $url = config('app.base_url') . '/?#/user/order';

        $tmp = [];
        foreach($courseLevels as $level) {
            $tmp[] = 'Level ' . $level . '课程';
        }
        $nameArr = explode('-', $name);
        $name =  trim($nameArr[1]) . ' - ' . implode('、', $tmp);

        $data = [
            'first'    => "支付失败，订单取消！\n",
            'keyword1' => [$tradeNo, '#FF6F6F'],
            'keyword2' => [$name, '#FF6F6F'],
            'keyword3' => ['¥' . $actualPrice . "\n", '#FF6F6F'],
            'remark'   => ['如果服务过程中有任何不满意的地方，拨打客服电话：4008558297或者微信直接回复', '#FF6F6F'],
        ];
        $socialAccount = UserInternal::getSocialAccount($userId);
        $this->send($socialAccount['openId'], $templateId, $url, $data);
    }
}
